package commandPatern;

import java.awt.CardLayout;
import java.sql.SQLException;

import gui.abstracts.AbstractPanel;
import gui.abstracts.ContainerAbstractObject;
import gui.containerDate.Nodes;
import gui.panels.PanelCardLayaut;
import gui.panels.PanelGroup;
import gui.panels.PanelStudent;
import gui.panels.PanelTree;
import gui.tables.TableGroup;
import gui.tables.TableStudent;

public class SwitchTree implements Command {
	
	private Nodes nodOld;
	private Nodes nodNew;
	private AbstractPanel defaultPanel;
	
	public SwitchTree(Nodes nodOld, AbstractPanel defaultPanel){
		this.nodOld = nodOld;
		this.defaultPanel = defaultPanel;
	}
	
	public void addNewNode(Nodes nodNew){
		this.nodNew = nodNew;
	}
	
	public Nodes getFirstNode(){
		return this.nodOld;
	}
	public void execute(Nodes temp ){
		if (temp.equals(Nodes.GROUPS)) {
			ContainerAbstractObject.getInstance().setAbstractPanel((AbstractPanel) PanelGroup.getInstance());
			ContainerAbstractObject.getInstance().setAbstractTable((TableGroup)((PanelGroup) PanelCardLayaut.getInstance().getPanelGroup()).getTable());
			((CardLayout) PanelCardLayaut.getInstance().getLayout()).show(PanelCardLayaut.getInstance(), Nodes.GROUPS.toString());
			PanelTree.getInstance().getJTree().setSelectionRow(1);
		} else if (temp.equals(Nodes.STUDENTS)) {
			ContainerAbstractObject.getInstance().setAbstractPanel((AbstractPanel) PanelCardLayaut.getInstance().getPanelStudent());
			ContainerAbstractObject.getInstance().setAbstractTable((TableStudent) ((PanelStudent) PanelCardLayaut.getInstance()	.getPanelStudent()).getTable());
			System.out.println("student");
			((CardLayout) PanelCardLayaut.getInstance().getLayout()).show(
					PanelCardLayaut.getInstance(), Nodes.STUDENTS.toString());
			PanelTree.getInstance().getJTree().setSelectionRow(2);
		}
	}
	@Override
	public void undo(){
		System.out.println("undo switch tree");
		execute(nodOld);		
	}

	@Override
	public void rendoo(){
		System.out.println("rendoo switch tree");
		execute(nodNew);
	}
}
